import popEvent from './event.js'
export default class myCom extends HTMLElement {
  constructor() {
    super();
    // console.log(this.attributes);
    let attr = this.attributes;
    this._data = {
      title: attr.title ? attr.title.value : '默认的标题',
      content: attr.content ? attr.content.value : '默认的内容',
    }
    this.render();
  }

  render() {
    this.obj = document.createElement('div');
    this.obj.innerHTML = `
    <div class="card-box">
      <div class="card">
        <!-- 背面 -->
        <div class="back"></div>
        <!-- 正面 -->
        <div class="front">
          <h2>李盼盼</h2>
          <p>性别：女</p>
          <p>爱好：吃饭、睡觉、打豆豆</p>
          <p>特长：腿特长</p>
          <p>体重：保密</p>
          <p>颜值：暴击</p>
        </div>
      </div>
    </div>
    `;
    this.append(this.obj);
  }

}

window.customElements.define('turn-card', myCom);


let style = document.createElement('style');
document.body.appendChild(style);
style.innerText = `
.card-box {
  width: 20%;
  max-width: 310px;
  height: 500px;
  /* 景深 */
  perspective: 900px;
}

.card {
  height: 100%;
  /* 开启3D */
  transform-style: preserve-3d;
  position: relative;
  transition: all .8s ease;
}

.card-box:hover .card {
  transform: rotateY(180deg);
}

.card div {
  height: 100%;
  position: absolute;
  border-radius: 30px;
  box-shadow: 4px 10px 40px 0px rgb(14, 13, 13);
  background-color: #fff;
  text-align: center;
  font-family: cursive;
  backface-visibility: hidden;
}

.front,
.back {
  width: 100%;
}

/* 正面 */
.front {
  z-index: 1;
  transform: rotateY(180deg);
}

.front p{
  text-align: left;
  text-indent: 2em;
}

/* 背面 */
.back {
  background-image: linear-gradient(to top, #a8edea 0%, #fed6e3 100%);
  z-index: 2;
  transform: rotateY(0deg);
}
`